<template>
	<view class="mine-page page">
		<view class="info-block">
			<template v-if="list.length>0">
				<view class="info-list" v-for="item in list" :key="item.id">
					<view class="left-item">
						<view class="substance">{{item.description}}</view>
						<view class="img-list">
							<template v-if="item.imageUrl">
								<image :src="item1" class="img-item" mode="scaleToFill" @click="previewImg(item)"
									v-for="(item1,index1) in item.imageUrl" :key="index1">
								</image>
							</template>
							<template v-if="item.videoUrl">
								<video id="myVideo" class="img-item" :src="item2" show-fullscreen-btn
									v-for="(item2,index2) in item.videoUrl" :key="index2"></video>
							</template>
						</view>
						<view class="address-item" v-if="item.address">
							<view class="iconfont icon-dingwei"></view>
							<view class="address">{{item.address}}</view>
						</view>
						<view class="time-item">
							<view class="iconfont icon-a-217shijian"></view>
							<view class="time">{{item.createTime}}</view>
						</view>
					</view>
				</view>
			</template>
			<view v-if="more==false&&list.length==0" class="empty">暂无数据</view>
			<view v-else-if="more==false&&list.length>0" class="empty">没有更多了</view>
		</view>
	</view>
</template>

<script>
	import {
		isMore
	} from '@/util/util'
	import {
		getReportList
	} from '@/api/complain.js'
	export default {
		data() {
			return {
				conf: {
					page: 1,
					limit: 20
				},
				more: true,
				list: []
			}
		},
		methods: {
			handleRefresh() {
				this.conf.page = 1;
				this.more = true
				this.getList('refresh');
			},
			getList(type = '') {
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				getReportList(this.conf).then(res => {
					let list = res.list || [];
					list.forEach((item, index) => {
						if (list[index].imageUrl) {
							list[index].imageUrl = list[index].imageUrl.split(',');
						}
						if (list[index].videoUrl) {
							list[index].videoUrl = list[index].videoUrl.split(',');
						}
					})
					this.list = type == 'refresh' ? list : [...this.list, ...list];
					this.more = isMore(this.conf.page, this.conf.limit, res.count)
				}).finally(() => {
					uni.stopPullDownRefresh();
				})
			},
			previewImg(current) {
				uni.previewImage({
					current,
					urls: current.url
				})
			},
		},
		onPullDownRefresh() {
			this.handleRefresh();
		},
		onReachBottom() {
			if (this.more) {
				this.conf.page++;
				this.getList();
			}
		},
		onLoad() {
			this.getList('refresh');
		}
	}
</script>

<style lang="scss" scoped>
	.mine-page {
		overflow: hidden;

		.info-block {
			padding: 30rpx;

			.info-list {
				background-color: #fff;
				display: flex;
				padding: 30rpx;
				border-radius: 20rpx;
				margin-bottom: 30rpx;

				.left-item {
					width: 100%;
					display: flex;
					flex-direction: column;

					.substance {
						margin-top: 10rpx;
						font-size: 30rpx;
						line-height: 50rpx;
						margin-bottom: 20rpx;
					}

					.img-list {
						width: 100%;
						display: flex;
						flex-direction: row;
						flex-wrap: wrap;
						margin-bottom: 30rpx;

						.img-item {
							width: calc((100% - 20rpx)/2);
							height: 200rpx;
							margin-right: 20rpx;
							margin-bottom: 15rpx;
							border-radius: 8px;
						}

						.img-item:nth-child(2n) {
							margin-right: 0;
						}
					}

					.address-item {
						display: flex;
						align-items: center;
						margin-top: 20rpx;

						.iconfont {
							color: #3565FF;
							font-size: 36rpx;
							margin-right: 10rpx;
						}

						.address {
							color: #3565FF;
							font-size: 30rpx;
						}
					}

					.time-item {
						display: flex;
						align-items: center;
						margin-top: 20rpx;

						.iconfont {
							color: #767676;
							font-size: 30rpx;
							margin-right: 12rpx;
							margin-left: 2rpx;
						}

						.time {
							color: #767676;
							font-size: 30rpx;
						}
					}
				}
			}
		}
	}
</style>